package com.jzbooks.config;


import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;



/**
 * @author mingPeng
 * @date 2021/4/17 21:09
 * @Description : Swagger 配置类
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
@Profile({"dev" , "test"})
public class Swagger2Config {

    @Bean
    public Docket jzBooksDocket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("jzbooks-api")
                .apiInfo(appApiInfo())
                .select()  // 通过.select()方法，去配置扫描接口,RequestHandlerSelectors配置如何扫描接口
                .apis(RequestHandlerSelectors.basePackage("com.jzbooks.controller"))   // 要扫描的包
                .paths(PathSelectors.any())      //扫描所有接口
                .build();
    }


    private ApiInfo appApiInfo(){
        return new ApiInfoBuilder()
                .title("jzbooks-api API")
                .description("鲸智图书管理系统 API")
//                .termsOfServiceUrl("http://localhost:8081")   //配置服务器地址
                .version("1.0")
                .build();
    }


}
